const Sequelize = require('sequelize')
const {sequelize} = require('./utils')

// 创建用户实体
const ProjectType = sequelize.define('project_type', {
        type_id: {
            type: Sequelize.INTEGER,
            primaryKey: true,
            autoIncrement: true
        },
        name: {
            type: Sequelize.STRING,
            allowNull: false
        },
        description: {
            type: Sequelize.STRING
        },
        deleted: {
            type: Sequelize.BOOLEAN,
            defaultValue: false
        }
    }
);
ProjectType.sync({force: false})
// /**插入新项目类型数据（添加） */
ProjectType.insertData = async (name, description) => {
    await ProjectType.sync({force: false})
    // 表已创建
    return ProjectType.create({
        name: name,
        description: description
    })
}

/** 更新项目数据 */
ProjectType.updateData = async (id, name, description) => {
    return ProjectType.update({
        name,description
    }, {
        where: {type_id : id}
    })
}
// 查找项目分类类型
ProjectType.findById = async (type_id) => {
    return ProjectType.findAll({where:{type_id} })
}
export {ProjectType}

